package com.xzlf.job.java;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class MyScheduledExecutorService {

    public static void main(String[] args) {
        // 创建任务队列
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
        // 执行任务
        scheduledExecutorService.scheduleAtFixedRate(
                () -> {
                    try {
                        TimeUnit.SECONDS.sleep(5);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "run Schedule1: " + new Date());
                    },
                1, 3, TimeUnit.SECONDS
        );
        scheduledExecutorService.scheduleAtFixedRate(
                () -> {

                    System.out.println(Thread.currentThread().getName() + "run Schedule2: " + new Date());
                    },
                1, 3, TimeUnit.SECONDS
        );
    }
}
